package com.zhuoyue;


import java.nio.charset.Charset;
import java.util.Timer;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 *
 * 虽然这种配置比较low，但是对于简单的客户端而言，就那样吧。
 *
 *
 *
 * @author Created by mr.liang
 */
public class ClientConfig {

    /** 服务重试时间 */
    private int reconnectionMill;

    /** 编码 */
    private Charset encodeCharset;

    /** 最大缓存数量 ， 小于或等于0表示无限长度 */
    private int maxCacheNum;

    /** 心跳间隔时间 */
    private int heartbeatTimeMill;

    /** 心跳包 */
    private String heartbeatPacket;

    /** 回调线程池 */
    private ThreadPoolExecutor threadPoolExecutor;

    /** 对端服务端口*/
    private int serverPort;

    /** 对端服务IP*/
    private String serverIp;

    /** 定时器（一个线程一个队列，阻塞等待的方式） */
    private Timer timer ;


    public ClientConfig(String serverIp,int serverPort) {
        this.serverPort = serverPort;
        this.serverIp = serverIp;
        timer = new Timer();

        reconnectionMill = 10_000;
        encodeCharset = Charset.forName("UTF-8");
        maxCacheNum = 1024;
        heartbeatTimeMill = 10_000;
        heartbeatPacket = "{\"type\":0}";
        threadPoolExecutor = (ThreadPoolExecutor)Executors.newFixedThreadPool(5);
    }

    public ClientConfig(int reconnectionMill, Charset encodeCharset, int maxCacheNum, int heartbeatTimeMill, String heartbeatPacket, ThreadPoolExecutor threadPoolExecutor) {
        this.reconnectionMill = reconnectionMill;
        this.encodeCharset = encodeCharset;
        this.maxCacheNum = maxCacheNum;
        this.heartbeatTimeMill = heartbeatTimeMill;
        this.heartbeatPacket = heartbeatPacket;
        this.threadPoolExecutor = threadPoolExecutor;
    }


    public int getReconnectionMill() {
        return reconnectionMill;
    }

    public Charset getEncodeCharset() {
        return encodeCharset;
    }

    public int getMaxCacheNum() {
        return maxCacheNum;
    }

    public int getHeartbeatTimeMill() {
        return heartbeatTimeMill;
    }

    public String getHeartbeatPacket() {
        return heartbeatPacket;
    }


    public ThreadPoolExecutor getThreadPoolExecutor() {
        return threadPoolExecutor;
    }

    public int getServerPort() {
        return serverPort;
    }

    public String getServerIp() {
        return serverIp;
    }

    public Timer getTimer() {
        return timer;
    }
}
